//
//  WBRetweetedCell.swift
//  WeiboTen
//
//  Created by ItHeiMa on 2017/7/9.
//  Copyright © 2017年 itHeima. All rights reserved.
//

import UIKit

class WBRetweetedCell: UITableViewCell {
    
    var statusViewModel: WBStatusViewModel? {
        didSet {
            originalView.statusViewModel = statusViewModel
            retweetedView.statusViewModel = statusViewModel
        }
    }
    
    lazy var originalView: WBOriginalView = WBOriginalView()
    lazy var retweetedView: WBRetweetedView = WBRetweetedView()
    lazy var statusBar: WBStatusBar = WBStatusBar()
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        self.setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

extension WBRetweetedCell {
    func setupUI () {
        //1. 添加子视图
        self.contentView.addSubview(originalView)
        self.contentView.addSubview(statusBar)
        self.contentView.addSubview(retweetedView)
        
        //2. 自动布局
        originalView.snp.makeConstraints { (make) in
            make.top.left.right.equalTo(self.contentView)
        }
        
        retweetedView.snp.makeConstraints { (make) in
            make.top.equalTo(originalView.snp.bottom)
            make.left.right.equalTo(self.contentView)
        }
        
        statusBar.snp.makeConstraints { (make) in
            make.top.equalTo(retweetedView.snp.bottom)
            make.left.right.equalTo(self.contentView)
            make.height.equalTo(36)
            //保证能够正确计算出行高
            make.bottom.equalTo(self.contentView)
        }
        
    }
}
